package com.itboye.ihomebank.adapter;

import java.util.ArrayList;
import java.util.List;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.HouseListBean.HouseItem;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.net.NetPublicParams;
import com.itboye.ihomebank.util.XImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 首页中显示的房屋列表
 */
public class HomeAdapter extends BaseAdapter {
	private Context context;

	private List<HouseItem> list;

	public HomeAdapter(Context context, List<HouseItem> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder = null;
		if (view == null) {
			holder = new ViewHolder();
			view = LayoutInflater.from(context).inflate(
					R.layout.item_home_adapter, null);
			holder.home_adapter = (ImageView) view
					.findViewById(R.id.home_adapter);
			holder.home_title = (TextView) view.findViewById(R.id.home_title);
			holder.home_xq = (TextView) view.findViewById(R.id.home_xq);
			holder.home_biaoqian_01 = (TextView) view
					.findViewById(R.id.home_biaoqian_01);
			holder.home_biaoqian_02 = (TextView) view
					.findViewById(R.id.home_biaoqian_02);
			holder.home_biaoqian_03 = (TextView) view
					.findViewById(R.id.home_biaoqian_03);
			holder.home_money = (TextView) view.findViewById(R.id.home_money);
			holder.home_danjia = (TextView) view.findViewById(R.id.home_danjia);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		XImageLoader.load(NetPublicConstant.IMAGE_URL
				+ list.get(position).getMainImg(), holder.home_adapter);
		holder.home_title.setText(list.get(position).getTitle());
		holder.home_xq.setText(list.get(position).getAddressDetail());
		holder.home_money.setVisibility(View.GONE);
		holder.home_danjia.setText(list.get(position).getRent() + "元/月");

		return view;
	}

	class ViewHolder {
		ImageView home_adapter;// 图片
		TextView home_title;// 标题
		TextView home_xq;// 详情
		TextView home_biaoqian_01, home_biaoqian_02, home_biaoqian_03;// 标签
		TextView home_money;// 价格
		TextView home_danjia;// 单价

	}

}
